
//资产背包，包括房子，车子，等固定资产
import { ccs } from "../../../util/services";
import { assetsType, companyType } from "../../gameType";
import { game } from "../game";
import { assetsBase, companyBase, ItemBase } from "../Item/ItemBase";
import { BagBase, BagData } from "./bagBase";

//公司的背包
export class companyBag extends BagBase<companyBase>{
    bagData: BagData = {buyNum: 0, items: [], itemCount: 0};
    constructor(data) {
        super(
            { buyNum: 0, items: [], itemCount: 0 },
            data.itemTypes,
            data.bagType
        );
    }
    addCompany(company: companyType) {
        //新建
        this.addItem(new companyBase(company));
    }
    delCompany(company: companyType) {
        //清算
        if(company.money < 0) {
            ccs.winMgr.showWin("toast", {msg: "请先偿还欠款"});
            return;
        }
        if(company.money < company.pay) {
            ccs.winMgr.showWin("toast", {msg: "无法支付所有支出"});
            return;
        }
        company.money -= company.pay;
        
        if(company.money > 0) {
            game.playerMgr.heroInfo.money += Math.trunc(company.money * 0.9);
        }
        this.delItem(company.id);

    }
    //结算
    payMoney() {
        let list: companyType[] = this.bag.items;
        list.forEach(val => {
            if(val.money < 0) {
                let escape = Math.trunc(val.workers * 0.2);
                val.workers -= escape//逃跑
                val.money -= val.pay;
                val.pay -= escape * val.wage;
            } else {
                val.money -= val.pay;
            }
            val.money -= val.rent;
        })
    }
}